home *** CD-ROM | disk | FTP | other *** search
- Path: gidora.kralizec.net.au!root
- From: rosko@zeta.org.au (Ross McKay)
- Newsgroups: comp.lang.c++
- Subject: Re: Watcom: corrupt this-pointer
- Date: Sat, 03 Feb 1996 02:26:10 GMT
- Organization: Soft Technologies
- Message-ID: <4eudvi$e84@gidora.kralizec.net.au>
- References: <31108A0B.108DC964@sp.zrz.tu-berlin.de>
- Reply-To: rosko@zeta.org.au
- NNTP-Posting-Host: dialup78.syd1.zeta.org.au
- X-Newsreader: Forte Free Agent 1.0.82
-
- (copy to emai)
-
- Olaf Lenzmann <olafbaje@sp.zrz.tu-berlin.de> wrote:
- >Hi there !
-
- >I have a really confusing problem with Watcom-C++ 10.0:
-
- >I have a cpp-Application with lots of self-defined classes,
- >compiled with a large memory model. When I create any of
- >my objects dynamically, the constructor seems to use a
- >corrput segment adress for the this-pointer. The offset
- >is ok, but anyway it results in a zillion general protection
- >faults. Borland C++ 4.52 does compile it allright though.
-
- >Any ideas ? I tried about every compiler switch possible...
-
- > Thanx, olaf
-
- Hi Olaf, I suspect one of the following:
-
- a) you have corrupted the program stack somewhere;
- a common way to do that is to return a pointer
- to a local (temporary) object, which is really
- a pointer to a place on the stack, and used it
- after returning from the function the object
- was defined in.
-
- b) you have an uninitialized or incorrectly assigned
- pointer to an object, which you dereference to
- access either a method of the object or a method
- of one of its member objects.
-
- e.g. a)
-
- int* F(int a)
- {
- int b;
- b = a;
- return &b; // <-- there be Evil!!
- }
-
- ....
- int* c = F(2);
- sprintf (buffer, "%d\n", *c);
- ....
-
- e.g. b)
- class SomeClass
- {
- public:
- SomeClass (void) {}
- void DoSomething (void);
- void DoSomethingElse (void) { this->c.Crash(); }
- private:
- SomeOtherClass c;
- };
-
- e.g. b.1)
-
- SomeClass* a; // <-- uninitialized!!
- a->DoSomething(); // <-- roll, crash, burn!!
-
- e.g. b.2)
-
- SomeClass* a; // <-- uninitialized!!
- a->DoSomethingElse(); // <-- this pointer trashed in
- // SomeOtherClass
-
- Hope this helps.
- Cheers,
- ------------------------------------------------------------------
- Ross McKay | snail: GPO Box 562, Sydney NSW 2001 Australia
- Soft Technologies | email: mailto:rosko@zeta.org.au
- Sydney, Australia | URL: http://www.zeta.org.au/~rosko
- ------------------------------------------------------------------
- The opinions expressed are my own, not those of Soft Technologies.
- "The beatings will continue, until staff morale improves."
-
-